import os

from openai import OpenAI

class EmbeddingHelper:

    def __init__(self):
        self.client = OpenAI(api_key= os.environ["OPENAI_API_KEY_ZHIHU"],base_url=os.environ["OPENAI_API_BASE_ZHIHU"])
        pass

    def getVector(self,text):
        # 向OpenAI API请求生成嵌入向量
        response = self.client.embeddings.create(
            input=text,
            model='text-embedding-3-small',  # 指定使用的模型
        )

        # 从响应中提取嵌入向量并返回
        embeddings = [data.embedding for data in response.data]
        return embeddings